package com.tju.resource.oauth.controller.tb;

import cn.hutool.json.JSONObject;
import com.tju.resource.annotation.Log;
import com.tju.resource.business.tb_bom.TbBomService;
import com.tju.resource.model.TbBom;
import com.tju.resource.result.Result;
import com.tju.resource.tool.enum_utils.FunctionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TbBomController {

    public final static String prefix = "bom";

    @Autowired
    TbBomService service;

    @PreAuthorize("hasAuthority('sys:bom:manage:list')")
    @PostMapping(prefix + "/getAll")
    @Log(type= FunctionType.List)
    public Result<List<TbBom>> getAll(@RequestBody JSONObject params) {
        return service.getAll(params);
    }

    @PreAuthorize("hasAuthority('sys:bom:manage:list')")
    @PostMapping(prefix + "/byNo")
    @Log(type= FunctionType.List)
    public Result<TbBom> byNo(@RequestBody JSONObject params) {
        return service.byNo(params);
    }

    @PreAuthorize("hasAuthority('sys:order:order:add')")
    @PostMapping(prefix + "/add")
    @Log(type= FunctionType.Add)
    public Result<Object> add(@RequestBody TbBom bom) {
        return service.add(bom);
    }

    @PreAuthorize("hasAuthority('sys:bom:manage:edit')")
    @PostMapping(prefix + "/upd")
    @Log(type= FunctionType.Modify)
    public Result<Object> upd(@RequestBody TbBom bom) {
        return service.upd(bom);
    }
}
